#include "Csdl.h"
#include "functions.h"

#include "Cmusic.h"
#include "Csound.h"

#include "Cfps.h"

SDL_Event event;

Uint8 *keystate=SDL_GetKeyState(NULL);



int main( int argc, char* args[] )
{


	Csdl sdl(true,true);
	sdl.SetVideoMode(400,300,false,32,"aaa");
	

	bool exit=false;	


Csound m("music/beat.wav");
Csound a("music/scratch.wav");
int frame=0;
Cfps timer(40);
int timea=SDL_GetTicks();
SDL_Surface *pic=loadbitmap("pic/back.png");
while(!exit)
	{
		
		
		if(SDL_PollEvent(&event))
		{
			if(event.type==SDL_QUIT)exit=true;

		}

	
	
		if(keystate[SDLK_ESCAPE])exit=true;
		sdl.ScreenRefresh();
			if(keystate[SDLK_1])m.play(2);
			if(keystate[SDLK_2])m.stop();
			if(keystate[SDLK_3])a.play(4);
			if(keystate[SDLK_4])a.stop();
			
			
			drawbitmap(1,1,pic,sdl.screensurface);
			timer.regulatefps();
			frame++;
			write(sdl.IntToString(frame),sdl.screensurface,0,0);
			write(sdl.IntToString(SDL_GetTicks() /1000),sdl.screensurface,0,40);
			
			
			int time2a=SDL_GetTicks();
			std::stringstream caption;
			caption<<"FPS: "<<frame/((time2a-timea)/1000.f);
			
			 SDL_WM_SetCaption( caption.str().c_str(), NULL );
			
			sdl.ScreenRefresh();
			
	}

	


	return 0;
}

